Closes #1363.
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_lib: bool,
flag_bin: Vec<String>,
flag_example: Vec<String>,
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
All of the trailing arguments are passed to the benchmark binaries generated
for filtering benchmarks and generally providing options configuring how they
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let ops = ops::TestOptions {
no_run: options.flag_no_run,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be built. If it is not given, then the
debug!("executing; cmd=cargo-build; args={:?}",
env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
flag_list: bool,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
arg_command: String,
arg_args: Vec<String>,
}
cargo [options]
Options:
- -h, --help Display this message
- -V, --version Print version info and exit
- --list List installed commands
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Display this message
+ -V, --version Print version info and exit
+ --list List installed commands
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
Some common cargo commands are:
build Compile the current project
*/
fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(flags.flag_verbose, flags.flag_quiet));
+ try!(config.shell().set_color_config(flags.flag_color.as_ref().map(|s| &s[..])));
init_git_transports(config);
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
--target TRIPLE Target triple to clean output for (default all)
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
If the --package argument is given, then SPEC is a package id specification
which indicates which package's artifacts should be cleaned out. If it is not
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
flag_open: bool,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_package: Option<String>,
}
--manifest-path PATH Path to the manifest to document
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
cargo fetch [options]
Options:
- -h, --help Print this message
- --manifest-path PATH Path to the manifest to fetch dependencies for
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --manifest-path PATH Path to the manifest to fetch dependencies for
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
If a lockfile is available, this command will ensure that all of the git
dependencies and/or registries dependencies are downloaded and locally
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
try!(ops::fetch(&root, config).map_err(|e| {
CliError::from_boxed(e, 101)
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
cargo generate-lockfile [options]
Options:
- -h, --help Print this message
- --manifest-path PATH Path to the manifest to generate a lockfile for
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --manifest-path PATH Path to the manifest to generate a lockfile for
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
ops::generate_lockfile(&root, config)
flag_reference: String,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
cargo git-checkout -h | --help
Options:
- -h, --help Print this message
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let Options { flag_url: url, flag_reference: reference, .. } = options;
let url = try!(url.to_url().map_err(|e| {
arg_token: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
cargo login [options] [<token>]
Options:
- -h, --help Print this message
- --host HOST Host to set the token for
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --host HOST Host to set the token for
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let token = match options.arg_token.clone() {
Some(token) => token,
None => {
struct Options {
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_bin: bool,
arg_path: String,
flag_name: Option<String>,
--name <name> Set the resulting package name
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let Options { flag_bin, arg_path, flag_name, flag_vcs, .. } = options;
flag_index: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_list: bool,
}
cargo owner [options] [<crate>]
Options:
- -h, --help Print this message
- -a, --add LOGIN Login of a user to add as an owner
- -r, --remove LOGIN Login of a user to remove as an owner
- -l, --list List owners of a crate
- --index INDEX Registry index to modify owners for
- --token TOKEN API token to use when authenticating
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ -a, --add LOGIN Login of a user to add as an owner
+ -r, --remove LOGIN Login of a user to remove as an owner
+ -l, --list List owners of a crate
+ --index INDEX Registry index to modify owners for
+ --token TOKEN API token to use when authenticating
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
This command will modify the owners for a package on the specified registry (or
default). Note that owners of a package can upload new versions, yank old
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let opts = ops::OwnersOptions {
krate: options.arg_crate,
token: options.flag_token,
struct Options {
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_manifest_path: Option<String>,
flag_no_verify: bool,
flag_no_metadata: bool,
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
ops::package(&root, config,
!options.flag_no_verify,
struct Options {
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_manifest_path: Option<String>,
arg_spec: Option<String>,
}
cargo pkgid [options] [<spec>]
Options:
- -h, --help Print this message
- --manifest-path PATH Path to the manifest to the package to clean
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --manifest-path PATH Path to the manifest to the package to clean
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
Given a <spec> argument, print out the fully qualified package id specifier.
This command will generate an error if <spec> is ambiguous as to which package
pub fn execute(options: Options,
config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone()));
let spec = options.arg_spec.as_ref().map(|s| &s[..]);
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_no_verify: bool,
}
cargo publish [options]
Options:
- -h, --help Print this message
- --host HOST Host to upload the package to
- --token TOKEN Token to use when uploading
- --no-verify Don't verify package tarball before publish
- --manifest-path PATH Path to the manifest to compile
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --host HOST Host to upload the package to
+ --token TOKEN Token to use when uploading
+ --no-verify Don't verify package tarball before publish
+ --manifest-path PATH Path to the manifest to compile
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let Options {
flag_token: token,
flag_host: host,
#[derive(RustcDecodable)]
struct Options {
flag_manifest_path: String,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
cargo read-manifest -h | --help
Options:
- -h, --help Print this message
- -v, --verbose Use verbose output
+ -h, --help Print this message
+ -v, --verbose Use verbose output
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>> {
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let path = Path::new(&options.flag_manifest_path);
let mut source = try!(PathSource::for_path(&path, config).map_err(|e| {
CliError::new(e.description(), 1)
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_release: bool,
arg_args: Vec<String>,
}
--manifest-path PATH Path to the manifest to execute
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
If neither `--bin` nor `--example` are given, then if the project only has one
bin target it will be run. Otherwise `--bin` specifies the bin target to run,
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
--manifest-path PATH Path to the manifest to fetch dependencies for
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
The specified target for the current package (or package specified by SPEC if
provided) will be compiled along with all of its dependencies. The specified
debug!("executing; cmd=cargo-rustc; args={:?}",
env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
flag_host: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
arg_query: String
}
cargo search [-h | --help]
Options:
- -h, --help Print this message
- --host HOST Host of a registry to search in
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --host HOST Host of a registry to search in
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let Options {
flag_host: host,
arg_query: query,
flag_bench: Vec<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_release: bool,
}
--manifest-path PATH Path to the manifest to build tests for
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
All of the trailing arguments are passed to the test binaries generated for
filtering tests and generally providing options configuring how they run. For
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let ops = ops::TestOptions {
no_run: options.flag_no_run,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
This command requires that a `Cargo.lock` already exists as generated by
`cargo build` or related commands.
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
let spec = options.flag_package.as_ref();
flag_manifest_path: String,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
}
pub const USAGE: &'static str = "
--manifest-path PATH Path to the manifest to verify
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
try!(config.shell().set_verbosity(args.flag_verbose, args.flag_quiet));
+ try!(config.shell().set_color_config(args.flag_color.as_ref().map(|s| &s[..])));
let mut contents = String::new();
let file = File::open(&args.flag_manifest_path);
cargo version [options]
Options:
- -h, --help Print this message
- -v, --verbose Use verbose output
+ -h, --help Print this message
+ -v, --verbose Use verbose output
+ --color WHEN Coloring: auto, always, never
";
pub fn execute(_: Options, _: &Config) -> CliResult<Option<()>> {
flag_index: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
+ flag_color: Option<String>,
flag_undo: bool,
}
cargo yank [options] [<crate>]
Options:
- -h, --help Print this message
- --vers VERSION The version to yank or un-yank
- --undo Undo a yank, putting a version back into the index
- --index INDEX Registry index to yank from
- --token TOKEN API token to use when authenticating
- -v, --verbose Use verbose output
- -q, --quiet No output printed to stdout
+ -h, --help Print this message
+ --vers VERSION The version to yank or un-yank
+ --undo Undo a yank, putting a version back into the index
+ --index INDEX Registry index to yank from
+ --token TOKEN API token to use when authenticating
+ -v, --verbose Use verbose output
+ -q, --quiet No output printed to stdout
+ --color WHEN Coloring: auto, always, never
The yank command removes a previously pushed crate's version from the server's
index. This command does not delete any data, and the crate will still be
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+ try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
try!(ops::yank(config,
options.arg_crate,
options.flag_vers,
pub use self::package_id_spec::PackageIdSpec;
pub use self::registry::Registry;
pub use self::resolver::Resolve;
-pub use self::shell::{Shell, MultiShell, ShellConfig, Verbosity};
+pub use self::shell::{Shell, MultiShell, ShellConfig, Verbosity, ColorConfig};
pub use self::source::{Source, SourceId, SourceMap, SourceSet, GitReference};
pub use self::summary::Summary;
use self::AdequateTerminal::{NoColor, Colored};
use self::Verbosity::{Verbose, Normal, Quiet};
+use self::ColorConfig::{Auto, Always, Never};
use util::errors::{human, CargoResult};
Quiet
}
+#[derive(Clone, Copy, PartialEq)]
+pub enum ColorConfig {
+ Auto,
+ Always,
+ Never
+}
+
#[derive(Clone, Copy)]
pub struct ShellConfig {
- pub color: bool,
- pub verbosity: Verbosity,
+ pub color_config: ColorConfig,
pub tty: bool
}
}
}
+ pub fn set_color_config(&mut self, color: Option<&str>) -> CargoResult<()> {
+ self.out.set_color_config(match color {
+ Some("auto") => Auto,
+ Some("always") => Always,
+ Some("never") => Never,
+
+ None => Auto,
+
+ Some(arg) => return Err(human(format!("argument for --color must be auto, always, or \
+ never, but found `{}`",
+ arg))),
+ });
+ Ok(())
+ }
+
pub fn get_verbose(&self) -> Verbosity {
self.verbosity
}
impl Shell {
pub fn create(out: Box<Write + Send>, config: ShellConfig) -> Shell {
- if config.tty && config.color {
+ // Check for cfg!(windows) as colored output on Windows can only be supported when a tty is
+ // present.
+ if !cfg!(windows) || config.tty {
let term = TerminfoTerminal::new(out);
term.map(|t| Shell {
terminal: Colored(Box::new(t)),
}
}
- pub fn verbose<F>(&mut self, mut callback: F) -> io::Result<()>
- where F: FnMut(&mut Shell) -> io::Result<()>
- {
- match self.config.verbosity {
- Verbose => return callback(self),
- _ => Ok(())
- }
- }
-
- pub fn concise<F>(&mut self, mut callback: F) -> io::Result<()>
- where F: FnMut(&mut Shell) -> io::Result<()>
- {
- match self.config.verbosity {
- Verbose => Ok(()),
- _ => return callback(self)
- }
+ pub fn set_color_config(&mut self, color_config: ColorConfig) {
+ self.config.color_config = color_config;
}
pub fn say<T: ToString>(&mut self, message: T, color: Color) -> io::Result<()> {
- match self.config.verbosity {
- Quiet => Ok(()),
- _ => {
- try!(self.reset());
- if color != BLACK { try!(self.fg(color)); }
- try!(write!(self, "{}\n", message.to_string()));
- try!(self.reset());
- try!(self.flush());
- Ok(())
- },
- }
+ try!(self.reset());
+ if color != BLACK { try!(self.fg(color)); }
+ try!(write!(self, "{}\n", message.to_string()));
+ try!(self.reset());
+ try!(self.flush());
+ Ok(())
}
pub fn say_status<T, U>(&mut self, status: T, message: U, color: Color)
}
fn fg(&mut self, color: color::Color) -> io::Result<bool> {
+ let colored = self.colored();
+
match self.terminal {
- Colored(ref mut c) => c.fg(color),
- NoColor(_) => Ok(false)
+ Colored(ref mut c) if colored => c.fg(color),
+ _ => Ok(false)
}
}
fn attr(&mut self, attr: Attr) -> io::Result<bool> {
+ let colored = self.colored();
+
match self.terminal {
- Colored(ref mut c) => c.attr(attr),
- NoColor(_) => Ok(false)
+ Colored(ref mut c) if colored => c.attr(attr),
+ _ => Ok(false)
}
}
fn supports_attr(&self, attr: Attr) -> bool {
+ let colored = self.colored();
+
match self.terminal {
- Colored(ref c) => c.supports_attr(attr),
- NoColor(_) => false
+ Colored(ref c) if colored => c.supports_attr(attr),
+ _ => false
}
}
fn reset(&mut self) -> io::Result<()> {
+ let colored = self.colored();
+
match self.terminal {
- Colored(ref mut c) => c.reset().map(|_| ()),
- NoColor(_) => Ok(())
+ Colored(ref mut c) if colored => c.reset().map(|_| ()),
+ _ => Ok(())
}
}
+
+ fn colored(&self) -> bool {
+ self.config.tty && Auto == self.config.color_config
+ || Always == self.config.color_config
+ }
}
impl Write for Shell {
use rustc_serialize::json::{self, Json};
use docopt::Docopt;
-use core::{Shell, MultiShell, ShellConfig, Verbosity};
+use core::{Shell, MultiShell, ShellConfig, Verbosity, ColorConfig};
use core::shell::Verbosity::{Verbose};
+use core::shell::ColorConfig::{Auto};
use term::color::{BLACK, RED};
pub use util::{CargoError, CliError, CliResult, human, Config, ChainError};
{
let mut config = None;
let result = (|| {
- config = Some(try!(Config::new(shell(Verbose))));
+ config = Some(try!(Config::new(shell(Verbose, Auto))));
let args: Vec<_> = try!(env::args_os().map(|s| {
s.into_string().map_err(|s| {
human(format!("invalid unicode in argument: {:?}", s))
}).collect());
callback(&args, config.as_ref().unwrap())
})();
- let mut verbose_shell = shell(Verbose);
+ let mut verbose_shell = shell(Verbose, Auto);
let mut shell = config.as_ref().map(|s| s.shell());
let shell = shell.as_mut().map(|s| &mut **s).unwrap_or(&mut verbose_shell);
process_executed(result, shell)
}
}
-pub fn shell(verbosity: Verbosity) -> MultiShell {
+pub fn shell(verbosity: Verbosity, color_config: ColorConfig) -> MultiShell {
let tty = isatty(libc::STDERR_FILENO);
let stderr = Box::new(io::stderr());
- let config = ShellConfig { color: true, verbosity: verbosity, tty: tty };
+ let config = ShellConfig { color_config: color_config, tty: tty };
let err = Shell::create(stderr, config);
let tty = isatty(libc::STDOUT_FILENO);
let stdout = Box::new(io::stdout());
- let config = ShellConfig { color: true, verbosity: verbosity, tty: tty };
+ let config = ShellConfig { color_config: color_config, tty: tty };
let out = Shell::create(stdout, config);
return MultiShell::new(out, err, verbosity);
let CliError { error, exit_code, unknown } = err;
let fatal = exit_code != 0; // exit_code == 0 is non-fatal error
-
let hide = unknown && shell.get_verbose() != Verbose;
if hide {
let _ = shell.err().say("An unknown error occurred", RED);
'(- 1 *)'{-h,--help}'[show help message]' \
'(- 1 *)'--list'[list installed commands]' \
'(- 1 *)'{-v,--verbose}'[use verbose output]' \
+ '(- 1 *)'--color'[colorization option]' \
'(- 1 *)'{-V,--version}'[show version information]' \
'1: :_cargo_cmds' \
'*:: :->args'
'(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
build)
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
clean)
'(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
'--target=[target triple(default:all)]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
config-for-key)
'--no-default-features[do not build the default features]' \
'--open[oen docs in browser after the build]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
fetch)
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
generate-lockfile)
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
git-checkout)
'--reference=[REF]' \
'--url=[URL]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
help)
'(-h, --help)'{-h,--help}'[show help message]' \
'--host=[Host to set the token for]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
new)
'--hg[initialize new mercurial repo]' \
'--no-git[no new git repo]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
owner)
'(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \
'--token[API token]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
package)
'--manifest-path=[path to manifest]' \
'--no-verify[do not build to verify contents]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
pkgid)
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
publish)
'--no-verify[Do not verify tarball until before publish]' \
'--token[Token to use when uploading]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
read-manifest)
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
run)
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
'*: :_normal' \
;;
'(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
'1: :_test_names' \
;;
'(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
'--precise=[update single dependency to PRECISE]: :' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
verify-project)
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
version)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
;;
yank)
'--token[API token]' \
'--undo[undo yank]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
+ '--color=[colorization option]' \
'--vers[yank version]' \
;;
esac
.TP
\fB\-v, \-\-verbose\fR
Use verbose output
+.TP
+\fB\-\-color\fR
+Configure coloring of output
.SH COMMANDS
local opt_help='-h --help'
local opt_verbose='-v --verbose'
local opt_quiet='-q --quiet'
- local opt_common="$opt_help $opt_verbose $opt_quiet"
+ local opt_color='--color'
+ local opt_common="$opt_help $opt_verbose $opt_quiet $opt_color"
local opt_pkg='-p --package'
local opt_feat='--features --no-default-features'
local opt_mani='--manifest-path'
use hamcrest::{assert_that};
use cargo::core::shell::{Shell, ShellConfig};
-use cargo::core::shell::Verbosity::{Verbose, Quiet};
+use cargo::core::shell::ColorConfig::{Auto,Always, Never};
use support::{Tap, shell_writes};
}
test!(non_tty {
- let config = ShellConfig { color: true, verbosity: Verbose, tty: false };
+ let config = ShellConfig { color_config: Auto, tty: false };
let a = Arc::new(Mutex::new(Vec::new()));
Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
});
test!(color_explicitly_disabled {
- let config = ShellConfig { color: false, verbosity: Verbose, tty: true };
+ let term = TerminfoTerminal::new(Vec::new());
+ if term.is_none() { return }
+
+ let config = ShellConfig { color_config: Never, tty: true };
let a = Arc::new(Mutex::new(Vec::new()));
Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
let term = TerminfoTerminal::new(Vec::new());
if term.is_none() { return }
- let config = ShellConfig { color: true, verbosity: Verbose, tty: true };
+ let config = ShellConfig { color_config: Auto, tty: true };
let a = Arc::new(Mutex::new(Vec::new()));
Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
color::RED).unwrap()));
});
-test!(quiet_shell {
- let config = ShellConfig { color: true, verbosity: Quiet, tty: true };
+test!(color_explicitly_enabled {
+ let term = TerminfoTerminal::new(Vec::new());
+ if term.is_none() { return }
+
+ let config = ShellConfig { color_config: Always, tty: false };
let a = Arc::new(Mutex::new(Vec::new()));
Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
- shell.say("Should be suppressed", color::BLACK).unwrap();
+ shell.say("Hey Alex", color::RED).unwrap();
});
-
let buf = a.lock().unwrap().clone();
assert_that(&buf[..],
- shell_writes(""));
+ shell_writes(colored_output("Hey Alex\n",
+ color::RED).unwrap()));
});
fn colored_output(string: &str, color: color::Color) -> io::Result<String> {